package com.google.android.gms.internal;

import android.annotation.TargetApi;
import android.content.Context;
import android.media.AudioManager;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.gms.common.internal.Hide;

@Hide
@zzabh
@TargetApi(14)
public final class zzanq implements AudioManager.OnAudioFocusChangeListener {
    private final AudioManager mAudioManager;
    private boolean zzdlm;
    private final zzanr zzdog;
    private boolean zzdoh;
    private boolean zzdoi;
    private float zzdoj = 1.0f;

    public zzanq(Context context, zzanr zzanr) {
        this.mAudioManager = (AudioManager) context.getSystemService(MimeTypes.BASE_TYPE_AUDIO);
        this.zzdog = zzanr;
    }

    private final void zztr() {
        boolean z = false;
        boolean z2 = this.zzdlm && !this.zzdoi && this.zzdoj > 0.0f;
        if (z2 && !this.zzdoh) {
            if (this.mAudioManager != null && !this.zzdoh) {
                if (this.mAudioManager.requestAudioFocus(this, 3, 2) == 1) {
                    z = true;
                }
                this.zzdoh = z;
            }
            this.zzdog.zzsn();
        } else if (!z2 && this.zzdoh) {
            if (this.mAudioManager != null && this.zzdoh) {
                if (this.mAudioManager.abandonAudioFocus(this) == 0) {
                    z = true;
                }
                this.zzdoh = z;
            }
            this.zzdog.zzsn();
        }
    }

    public final float getVolume() {
        float f = this.zzdoi ? 0.0f : this.zzdoj;
        if (this.zzdoh) {
            return f;
        }
        return 0.0f;
    }

    public final void onAudioFocusChange(int i) {
        this.zzdoh = i > 0;
        this.zzdog.zzsn();
    }

    public final void setMuted(boolean z) {
        this.zzdoi = z;
        zztr();
    }

    public final void zzb(float f) {
        this.zzdoj = f;
        zztr();
    }

    public final void zzto() {
        this.zzdlm = true;
        zztr();
    }

    public final void zztp() {
        this.zzdlm = false;
        zztr();
    }
}
